const common = {
  operActivity: {
    /**
     * 默认活动结构
     */
    defaultActivity: {
      regions: [[1]],
      time: [],
      valids: [],

      createDept: 0,
      createBy: 0,
      createTime: '',
      updateBy: 0,
      updateTime: '',
      params: {
        property1: {},
        property2: {}
      },
      activityType: '1',
      scope: '',
      orderType: '1',
      activityName: '',
      activityDescription: '',
      startTime: '',
      endTime: '',
      orderAmount: 0,
      qrCode: '',
      status: '',
      coupon: {
        createDept: 0,
        createBy: 0,
        createTime: '',
        updateBy: 0,
        updateTime: '',
        params: {
          property1: {},
          property2: {}
        },
        activityId: 0,
        couponType: '1',
        validFrom: '',
        validTo: '',
        distributionRatio: 0,
        claimCount: 0,
        totalQuantity: 0,
        participantsQuantity: 0,
        collectedQuantity: 0,
        verifiedQuantity: 0,
        optionsBo: {
          experience: {
            durationMs: 0
          },
          discounts: [
            {
              minOrderAmount: 0,
              discountAmount: 0
            }
          ],
          cash: {
            cashType: '',
            denomination: 0,
            randomFloorAmount: 0,
            randomRoofAmount: 0
          }
        },
        redemptionPeriod: 60,
        options: ''
      },
      points: {
        createDept: 0,
        createBy: 0,
        createTime: '',
        updateBy: 0,
        updateTime: '',
        params: {
          property1: {},
          property2: {}
        },
        activityId: 0,
        exchangeRate: 0,
        discountRate: 0
      },
      activityVendors: [
        {
          createDept: 0,
          createBy: 0,
          createTime: '',
          updateBy: 0,
          updateTime: '',
          params: {
            property1: {},
            property2: {}
          },
          id: 0,
          activityId: 0,
          vendorId: 0
        }
      ],
      activityRegions: [
        {
          createDept: 0,
          createBy: 0,
          createTime: '',
          updateBy: 0,
          updateTime: '',
          params: {
            property1: {},
            property2: {}
          },
          id: 0,
          activityId: 0,
          regionCode: '0'
        }
      ]
    },
    /**
     * 活动管理数据匹配
     * @param object1
     * @param object2
     * @returns
     */
    verifyDataIntegrity(object1, object2) {
      var obj1 = JSON.parse(JSON.stringify(object1));
      var obj2 = JSON.parse(JSON.stringify(object2));

      //数据结构匹配
      if (obj2.activityCouponVo) {
        let options = JSON.parse(obj2.activityCouponVo.options);
        let couponType = obj2.activityCouponVo.couponType;
        let optionsBo = {};
        switch (couponType) {
          case '1':
            optionsBo = { cash: options };
            break;
          case '2':
            optionsBo = { discounts: options };
            break;
          case '3':
            optionsBo = { experience: options };
            break;
        }
        obj2.activityCouponVo.optionsBo = optionsBo;
        obj2.coupon = obj2.activityCouponVo;
      }
      if (obj2.activityPointsVo) {
        obj2.points = obj2.activityPointsVo;
        obj2.coupon = {
          couponType: '0'
        };
      }

      function recursive(obj1, obj2) {
        for (var key in obj1) {
          var item1 = obj1[key];
          var item2 = obj2[key];
          if (typeof item1 !== 'object' && item2 === undefined) {
            obj2[key] = item1;
          } else if (typeof item1 === 'object' && item2 === undefined) {
            obj2[key] = item1;
          } else if (typeof item1 === 'object' && typeof item2 === 'object') {
            recursive(item1, item2);
          }
        }
      }
      recursive(obj1, obj2);

      //拼接字段处理
      let scope = obj2.scope;

      obj2.regions = [];
      if (scope == 1) {
        obj2.regions.push([1]);
      } else if (scope == 3) {
        obj2.activityRegions.forEach((item) => {
          obj2.regions.push([scope, item.regionCode]);
        });
      } else if (scope == 2) {
        //酒店
        obj2.activityVendors.forEach((item) => {
          obj2.regions.push([scope, item.vendorId]);
        });
      }

      //优惠过期时间
      obj2.valids = [obj2.coupon.validFrom, obj2.coupon.validTo];

      //活动过期时间
      obj2.time = [obj2.startTime, obj2.endTime];

      //活动类型处理
      if (obj2.activityType == '2' || obj2.coupon.couponType == '') {
        obj2.coupon.couponType = '0';
      }

      obj2.coupon.optionsBo.cash.denomination /= 100;
      obj2.coupon.optionsBo.cash.randomFloorAmount /= 100;
      obj2.coupon.optionsBo.cash.randomRoofAmount /= 100;
      obj2.coupon.optionsBo.discounts[0].minOrderAmount /= 100;
      obj2.coupon.optionsBo.discounts[0].discountAmount /= 100;

      return obj2;
    }
  },
  //日期格式化
  dateFormat(date) {
    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const day = date.getDate().toString().padStart(2, '0');
    const hour = date.getHours().toString().padStart(2, '0');
    const minite = date.getMinutes().toString().padStart(2, '0');
    const second = date.getSeconds().toString().padStart(2, '0');

    const formattedDate = `${year}-${month}-${day} ${hour}:${minite}:${second}`;
    return formattedDate;
  },

  /**
   * 匹配结果
   */
  marchType(value, types) {
    for (let i = 0; i < types.length; i++) {
      let type = types[i];
      if (type.value == value) return type.label;
    }
  }
};
export default common;
